Xbasic

a5Helper_findRecordInSQLTable Function

Syntax

dim result as p = a5Helper_findRecordInSQLTable (c connectionstring, c tablename, a findwhatValue [,c fieldlist [, L treatcommaasor [ , C pagesizeC [, c pageNumberC [, n maxrows [ c currentPageNumberC [,c Order]]]]]]])

Arguments

connectionstringCharacter

The connection string to the SQL database

tablenameCharacter

The name of the table to be queried

findwhatValueAny Type

Can be either a string or a typed value (e.g. 5 - type N) or an array of values to find. If a string, can be a comma delimited list of values (e.g. Paris,London). If a comma delimited string then the treatcommaasor paramater must be set to .t. If an array, the items in the array must correctly typed. See example below

fieldlistCharacter

If blank or "*", all fields of the appropriate type are searched. Can specify a comma delimited list of fields to search. For example, if findwhatValue is a datetime value and fieldlist is blank, then all datetime fields in the table are searched.

treatcommaasorLogical

If findWhatValue is a string, determines if the function should find the literal string (that includes a comma, e.g. "value, with a comma in it"), or should find records matching any of the values in the string (e.g. if findwhatValue is London,Paris find records matching London, or Paris).

pagesizeCCharacter

If you want to paginate the result, specify the page size. If pagesizeC is a blank value, then all matching records (subject to the maxrows constraint) are returned.

pageNumberCCharacter

Target page number. Only meaningful if pagesizeC is not blank. Can be an explicit page (e.g. "1", "5", "7", etc), or a relative page (e.g. first, previous, next or last) . If pageNumberC is next or previous, then the currentPageNumberC parameter must be supplied.

maxrowsNumeric

Maximum number of rows to return. Defaults to 1,000. Set to 0 to return all rows. Only relevant if pageSizeC is blank.

currentPageNumberCCharacter

Current page number. Only needed if pageNumberC is set to next or previous.

OrderCharacter

Order By fields using SQL syntax (e.g. Lastname, Firstname DESC)

Returns

resultPointer

Returns an object with these properties: error: .t. or .f. - indicates if there was any type of error, errorText - if error is .t., description of the error, data - the JSON data returned by the query, pageSize - the page size, pageNumber - the page number, recordCount - the number of records in the query, pageCount - the number of pages of records in the query, sql - the SQL statement that was executed, argumentsxml - the xml for the sql::arguments object used when the SQL was executed.

Description

Returns records from a SQL table that contain any fields that match the search criteria.

Discussion

The a5Helper_findRecordInSQLTable() function finds records in a SQL table where the search value is found in any of the fields in the table (i.e. a keyword search). If the search value is of type character, all of the character fields in the table are searched. If the search value is of type T (dateTime value), all of the dateTime fields in the table are searched, and so on. For character values, the search is for records where the search value is contained in the search field. For other data types, the search is for records where the search field equals the search value.